package com.mosue.sample.sso.employee.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class OAuth2RestTemplateConfiguration {

    @Qualifier("oauth2ClientContext")
    @Autowired
    private OAuth2ClientContext context;
    @Autowired
    private OAuth2ProtectedResourceDetails employee;


    @Bean
    public OAuth2RestTemplate employeeRestTmplate() {
        OAuth2RestTemplate rt = new OAuth2RestTemplate(employee, context);
//        List messageConverters = new ArrayList();
//        messageConverters.add(new SourceHttpMessageConverter());
//        messageConverters.add(new FormHttpMessageConverter());
//        messageConverters.add(new MappingJackson2HttpMessageConverter());
//        rt.setMessageConverters(messageConverters);
        return rt;
    }

    @Bean
    @ConfigurationProperties("security.oauth2.employee")
    public OAuth2ProtectedResourceDetails employee() {
        AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
        return details;
    }
}
